Learn R Programming

ChainLadder (version 0.1.7)

triangle S3 Methods: Generic functions for triangles

Description

Functions to ease the work with triangle shaped matrix data. A 'triangle' is a matrix with some generic functions. Triangles are usually stored in a 'long' format in data bases. The function as.triangle can transform a data.frame into a triangle shape.

Usage

## S3 method for class 'matrix':
as.triangle(Triangle,origin="origin", dev="dev", value="value",...)
## S3 method for class 'data.frame':
as.triangle(Triangle, origin="origin", dev="dev", value="value",...)
## S3 method for class 'triangle':
as.data.frame(x, row.names=NULL, optional, lob=NULL, na.rm=FALSE, ...)
as.triangle(Triangle, origin="origin", dev="dev", value="value",...)
## S3 method for class 'triangle':
plot(x, type = "b", xlab = "dev. period", ylab = NULL, lattice=FALSE, ...)

Arguments

Triangle
a triangle
origin
name of the origin period, default is "origin".
dev
name of the development period, default is "dev".
value
name of the value, default is "value".
row.names
default is set to NULL an will merge origin and dev. period to create row names.
lob
default is NULL. The idea is to use lob (line of business) as an additional column to label a triangle in a long format, see the examples for more details.
optional
not used
na.rm
logical. Remove missing values?
x
a matrix of class 'triangle'
xlab
a label for the x axis, defaults to 'dev. period'
ylab
a label for the y axis, defaults to NULL
lattice
logical. If FALSE the function matplot is used to plot the developments of the triangle in one graph, otherwise the xyplot function o
type
type, see plot.default
...
arguments to be passed to other methods

Warning

Please note that for the function as.triangle the origin and dev. period columns have to be of type numeric or a character which can be converted into numeric.

Also note that when converting from a data.frame to a matrix with as.triangle, multiple records with the same origin and dev will be aggregated.

Examples

Run this code
GenIns
plot(GenIns)
plot(GenIns, lattice=TRUE)


## Convert long format into triangle
## Triangles are usually stored as 'long' tables in data bases
head(GenInsLong)
as.triangle(GenInsLong, origin="accyear", dev="devyear", "incurred claims")

X <- as.data.frame(RAA)
head(X)

Y <- as.data.frame(RAA, lob="General Liability")
head(Y)

Run the code above in your browser using DataLab